﻿namespace HeritageAcademy.Shared.Languages
{
    public class Russian
    {
        public string Grammar(Word word, int number)
        {
            var rightword = string.Empty;
            switch (word)
            {
                case Word.Minute:
                    rightword = RussianMinutesGrammar(number);
                    break;
                case Word.Hour:
                    rightword = RussianHoursGrammar(number);
                    break;
                case Word.Day:
                    rightword = RussianDaysGrammar(number);
                    break;
                case Word.Week:
                    rightword = RussianWeeksGrammar(number);
                    break;
                case Word.Time:
                    rightword = RussianTimesGrammar(number);
                    break;
                case Word.Test:
                    rightword = RussianTestGrammar(number);
                    break;
            }
            return rightword;
        }

        #region Grammar

        private static string RussianMinutesGrammar(int m)
        {
            var minutes = string.Empty;
            if (m == 1 || m == 21 || m == 31 || m == 41 || m == 51)
            {
                minutes = "минута";
            }
            if ((m >= 2 & m <= 4) || (m >= 22 & m <= 24) || (m >= 32 & m <= 34) ||
                (m >= 42 & m <= 44) || (m >= 52 & m <= 54))
            {
                minutes = "минуты";
            }
            if (m == 0 || (m >= 5 & m <= 20) || (m >= 25 & m <= 30) ||
                (m >= 35 & m <= 40) || (m >= 45 & m <= 50) || (m >= 55 & m < 60))
            {
                minutes = "минут";
            }
            return minutes;
        }

        private static string RussianHoursGrammar(int h)
        {
            var hours = string.Empty;
            if (h == 1 || h == 21 || h == 31 || h == 41 || h == 51)
            {
                hours = "час";
            }
            if ((h >= 2 & h <= 4) || (h >= 22 & h <= 24) || (h >= 32 & h <= 34) ||
                (h >= 42 & h <= 44) || (h >= 52 & h <= 54))
            {
                hours = "часа";
            }
            if (h == 0 || (h >= 5 & h <= 20) || (h >= 25 & h <= 30) ||
                (h >= 35 & h <= 40) || (h >= 45 & h <= 50) || (h >= 55 & h < 60))
            {
                hours = "часов";
            }
            return hours;
        }

        private static string RussianDaysGrammar(int d)
        {
            var days = string.Empty;
            if (d == 1 || d == 21 || d == 31 || d == 41 || d == 51)
            {
                days = "день";
            }
            if ((d >= 2 & d <= 4) || (d >= 22 & d <= 24) || (d >= 32 & d <= 34) ||
                (d >= 42 & d <= 44) || (d >= 52 & d <= 54))
            {
                days = "дня";
            }
            if (d == 0 || (d >= 5 & d <= 20) || (d >= 25 & d <= 30) ||
                (d >= 35 & d <= 40) || (d >= 45 & d <= 50) || (d >= 55 & d < 60))
            {
                days = "дней";
            }
            return days;
        }

        private static string RussianWeeksGrammar(int w)
        {
            var weeks = string.Empty;
            if (w == 1 || w == 21 || w == 31 || w == 41 || w == 51)
            {
                weeks = "неделя";
            }
            if ((w >= 2 & w <= 4) || (w >= 22 & w <= 24) || (w >= 32 & w <= 34) ||
                (w >= 42 & w <= 44) || (w >= 52 & w <= 54))
            {
                weeks = "недели";
            }
            if (w == 0 || (w >= 5 & w <= 20) || (w >= 25 & w <= 30) ||
                (w >= 35 & w <= 40) || (w >= 45 & w <= 50) || (w >= 55 & w < 60))
            {
                weeks = "недель";
            }
            return weeks;
        }

        private static string RussianTimesGrammar(int t)
        {
            var times = string.Empty;
            if (t == 0 || t == 1 || t == 21 || t == 31 || t == 41 || t == 51 ||
                (t >= 5 & t <= 20) || (t >= 25 & t <= 30) ||
                (t >= 35 & t <= 40) || (t >= 45 & t <= 50) || (t >= 55 & t < 60))
            {
                times = "раз";
            }
            if ((t >= 2 & t <= 4) || (t >= 22 & t <= 24) || (t >= 32 & t <= 34) ||
                (t >= 42 & t <= 44) || (t >= 52 & t <= 54))
            {
                times = "раза";
            }
            return times;
        }

        private static string RussianTestGrammar(int t)
        {
            var test = string.Empty;
            if (t == 1 || t == 21 || t == 31 || t == 41 || t == 51)
            {
                test = "тест";
            }
            if ((t >= 2 & t <= 4) || (t >= 22 & t <= 24) || (t >= 32 & t <= 34) ||
                (t >= 42 & t <= 44) || (t >= 52 & t <= 54))
            {
                test = "теста";
            }
            if (t == 0 || (t >= 5 & t <= 20) || (t >= 25 & t <= 30) ||
                (t >= 35 & t <= 40) || (t >= 45 & t <= 50) || (t >= 55 & t < 60))
            {
                test = "тестов";
            }
            return test;
        }

        #endregion

        public enum Word
        {
            Minute,
            Hour,
            Day,
            Week,
            Time,
            Test
        }
    }
}